function sort(arr){
    for(var i=0;i<arr.length-1;i++){
        for(var j=0;j<arr.length-1-i;j++){
            if(arr[j]>arr[j+1]){
                var temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp
            }
          

        }
    }
    return arr
}
// console.log( sort([1,3,2,1,5,6,1]));
function youDa(arr){
    for(let i=0;i<arr.length;i++){
        let over = true 
        for(let j=0;j<arr.length-i-1;j++){
            if(arr[j+1]<arr[j]){
                let temp = arr[j]
                arr[j]=arr[j+1]
                arr[j+1]=temp

                over = false
            }
            
        }
        if(over){//已排好提前结束
            return arr;
        }
        console.log('第'+(i+1)+'轮：',arr.join(','))
    }
    return arr;
}
console.log( youDa([5,3,7,5,6,4,2]));